﻿Public Class TMyColumnTypes
    Implements System.IDisposable

    Private _List As New List(Of TMyColumnType)
    Public Sub New()
        InitNumeric()
        InitDateTime()
        InitString()
        InitSpatial()
    End Sub
    Public ReadOnly Property Count() As Integer
        Get
            Return _List.Count
        End Get
    End Property

    Public ReadOnly Property DataLength(ByVal AColumn As TMyTableColumn) As String
        Get
            If AColumn.ColumnType.Contains("(") Then
                Dim sTmp1 As String() = AColumn.ColumnType.Split("("c)
                Dim s1 As String = sTmp1(1)
                If s1.Contains(")") Then
                    Dim sTmp2 As String() = s1.Split(")"c)
                    Return sTmp2(0)
                End If
            End If
            Return String.Empty
        End Get
    End Property

    Public ReadOnly Property DataType(ByVal ADataTypeName As String) As TMyColumnType.TColumnType
        Get
            For i As Integer = 0 To _List.Count - 1
                If _List(i).ColumnTypeName.Equals(ADataTypeName) Then
                    Return _List(i).ColumnType
                End If
            Next
            Return TMyColumnType.TColumnType.dtNumeric
        End Get
    End Property
    Default Public ReadOnly Property Items(ByVal Index As Integer) As TMyColumnType
        Get
            Return _List(Index)
        End Get
    End Property
    Private Sub InitNumeric()
        Dim item As TMyColumnType = Nothing
        item = New TMyColumnType("TINYINT", TMyColumnType.TColumnType.dtNumeric)
        _List.Add(item)
        item = New TMyColumnType("SMALLINT", TMyColumnType.TColumnType.dtNumeric)
        _List.Add(item)
        item = New TMyColumnType("MEDIUMINT", TMyColumnType.TColumnType.dtNumeric)
        _List.Add(item)
        item = New TMyColumnType("INT", TMyColumnType.TColumnType.dtNumeric)
        _List.Add(item)
        item = New TMyColumnType("BIGINT", TMyColumnType.TColumnType.dtNumeric)
        _List.Add(item)
        item = New TMyColumnType("DECIMAL", TMyColumnType.TColumnType.dtNumeric)
        _List.Add(item)
        item = New TMyColumnType("FLOAT", TMyColumnType.TColumnType.dtNumeric)
        _List.Add(item)
        item = New TMyColumnType("DOUBLE", TMyColumnType.TColumnType.dtNumeric)
        _List.Add(item)
        item = New TMyColumnType("REAL", TMyColumnType.TColumnType.dtNumeric)
        _List.Add(item)
        item = New TMyColumnType("BIT", TMyColumnType.TColumnType.dtNumeric)
        _List.Add(item)
        item = New TMyColumnType("BOOLEAN", TMyColumnType.TColumnType.dtNumeric)
        _List.Add(item)
        item = New TMyColumnType("SERIAL", TMyColumnType.TColumnType.dtNumeric)
        _List.Add(item)
    End Sub
    Private Sub InitDateTime()
        Dim item As TMyColumnType = Nothing
        item = New TMyColumnType("DATE", TMyColumnType.TColumnType.dtDateTime)
        _List.Add(item)
        item = New TMyColumnType("DATETIME", TMyColumnType.TColumnType.dtDateTime)
        _List.Add(item)
        item = New TMyColumnType("TIMESTAMP", TMyColumnType.TColumnType.dtDateTime)
        _List.Add(item)
        item = New TMyColumnType("TIME", TMyColumnType.TColumnType.dtDateTime)
        _List.Add(item)
        item = New TMyColumnType("YEAR", TMyColumnType.TColumnType.dtDateTime)
        _List.Add(item)
    End Sub
    Private Sub InitString()
        Dim item As TMyColumnType = Nothing
        item = New TMyColumnType("CHAR", TMyColumnType.TColumnType.dtString)
        _List.Add(item)
        item = New TMyColumnType("VARCHAR", TMyColumnType.TColumnType.dtString)
        _List.Add(item)
        item = New TMyColumnType("TINYTEXT", TMyColumnType.TColumnType.dtString)
        _List.Add(item)
        item = New TMyColumnType("TEXT", TMyColumnType.TColumnType.dtString)
        _List.Add(item)
        item = New TMyColumnType("MEDIUMTEXT", TMyColumnType.TColumnType.dtString)
        _List.Add(item)
        item = New TMyColumnType("LONGTEXT", TMyColumnType.TColumnType.dtString)
        _List.Add(item)
        item = New TMyColumnType("BINARY", TMyColumnType.TColumnType.dtString)
        _List.Add(item)
        item = New TMyColumnType("VARBINARY", TMyColumnType.TColumnType.dtString)
        _List.Add(item)
        item = New TMyColumnType("TINYBLOB", TMyColumnType.TColumnType.dtString)
        _List.Add(item)
        item = New TMyColumnType("MEDIUMBLOB", TMyColumnType.TColumnType.dtString)
        _List.Add(item)
        item = New TMyColumnType("BLOB", TMyColumnType.TColumnType.dtString)
        _List.Add(item)
        item = New TMyColumnType("LONGBLOB", TMyColumnType.TColumnType.dtString)
        _List.Add(item)
        item = New TMyColumnType("ENUM", TMyColumnType.TColumnType.dtString)
        _List.Add(item)
        item = New TMyColumnType("SET", TMyColumnType.TColumnType.dtString)
        _List.Add(item)
    End Sub
    Private Sub InitSpatial()
        Dim item As TMyColumnType = Nothing
        item = New TMyColumnType("GEOMETRY", TMyColumnType.TColumnType.dtSpatial)
        _List.Add(item)
        item = New TMyColumnType("POINT", TMyColumnType.TColumnType.dtSpatial)
        _List.Add(item)
        item = New TMyColumnType("LINESTRING", TMyColumnType.TColumnType.dtSpatial)
        _List.Add(item)
        item = New TMyColumnType("POLYGON", TMyColumnType.TColumnType.dtSpatial)
        _List.Add(item)
        item = New TMyColumnType("MULTIPOINT", TMyColumnType.TColumnType.dtSpatial)
        _List.Add(item)
        item = New TMyColumnType("MULTILINESTRING", TMyColumnType.TColumnType.dtSpatial)
        _List.Add(item)
        item = New TMyColumnType("MULTIPOLYGON", TMyColumnType.TColumnType.dtSpatial)
        _List.Add(item)
        item = New TMyColumnType("GEOMETRYCOLLECTION", TMyColumnType.TColumnType.dtSpatial)
        _List.Add(item)
    End Sub

    Private disposedValue As Boolean = False        ' 重複する呼び出しを検出するには

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                ' TODO: 他の状態を解放します (マネージ オブジェクト)。
            End If
            _List.Clear()
            _List = Nothing
            ' TODO: ユーザー独自の状態を解放します (アンマネージ オブジェクト)。
            ' TODO: 大きなフィールドを null に設定します。
        End If
        Me.disposedValue = True
    End Sub

#Region " IDisposable Support "
    ' このコードは、破棄可能なパターンを正しく実装できるように Visual Basic によって追加されました。
    Public Sub Dispose() Implements IDisposable.Dispose
        ' このコードを変更しないでください。クリーンアップ コードを上の Dispose(ByVal disposing As Boolean) に記述します。
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

End Class
